package de.uni.muenster.idw2.xml;


import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import de.uni.muenster.idw2.data.BBBuilding;
import de.uni.muenster.idw2.data.BoundingBox;

public class BBXMLHandler extends DefaultHandler{
	
	private BoundingBox boundingBox;
	

	@Override
	public void startDocument() throws SAXException {
	}
	
	@Override
	public void endDocument() throws SAXException {
	}
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		
		if(localName.equals("buildingsbbox")){
			double lon_bottom_left = Double.parseDouble(attributes.getValue("lon_bottom_left"));
			double lon_top_right = Double.parseDouble(attributes.getValue("lon_top_right"));
			double lat_bottom_left = Double.parseDouble(attributes.getValue("lat_bottom_left"));
			double lat_top_right = Double.parseDouble(attributes.getValue("lat_top_right"));
			boundingBox = new BoundingBox(lon_bottom_left, lon_top_right, lat_bottom_left, lat_top_right);
		}
		else if(localName.equals("building")){
			double lon = Double.parseDouble(attributes.getValue("lon"));
			double lat = Double.parseDouble(attributes.getValue("lat"));
			String path = attributes.getValue("xmlpath");
			String name = attributes.getValue("name");
			String description = attributes.getValue("description");
			String imgPath = attributes.getValue("img");
			BBBuilding bbBuilding = new BBBuilding(lon, lat, path, name, description, imgPath);
			boundingBox.addBBBuilding(bbBuilding);
		}
	}
	
	
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
	}
	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		
	}
	
	public BoundingBox getBBBuildings(){
		return boundingBox;
	}
	
}
